package Controller;

import java.io.IOException;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class unbindServlet
 */
@WebServlet("/unbindServlet")
public class unbindServlet extends SerchBindServlet {
	private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public unbindServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		bindName=request.getParameter("bindName");
		bindValue=request.getParameter("bindValue");
		try {
			if(bindName!=null&&bindValue==(String)ctx.lookup(bindName))
			{
				ctx.unbind(bindName);
				response.getOutputStream().print("unbind successfully");
			}
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			response.getOutputStream().print("failed");
			e.printStackTrace();
		}	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
